find a duplicate entry in an array in constant space and O(n) time [closed]

Posted by Anubhav Agarwal on Stack Overflow See other posts from Stack Overflow or by Anubhav Agarwal
Published on 2011-11-24T17:35:46Z Indexed on 2011/11/24 17:50 UTC
Read the original article Hit count: 231

Possible Duplicate:
Algorithm to find a duplicate entry in constant space and O(n) time

Given an array of N integer such that only one integer is repeated. Find the repeated integer in O(n) time and constant space. There is no range for the value of integers or the value of N

For example given an array of 6 integers as 23 45 67 87 23 47. The answer is 23 (I hope this covers ambiguous and vague part)

I searched on the net but was unable to find any such question in which range of integers was not fixed. Also here is an example that answers a similar question to mine but here he created a hash table with the highest integer value in C++.But the cpp does not allow such to create an array with 2^64 element(on a 64-bit computer).

© Stack Overflow or respective owner

Related posts about c++

Related posts about algorithm